package org.seafloor.common.tag;

import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;

import org.seafloor.common.model.SystemConstants;
import org.seafloor.system.model.UserVO;

public class RoleEqualTag extends BodyTagSupport {
	private String type;

	@Override
	public int doStartTag() throws JspException {
		JspWriter out = this.pageContext.getOut();
		HttpSession session = pageContext.getSession();
		UserVO userVO = (UserVO) session
				.getAttribute(SystemConstants.SESSION_USERMESSAGE);
		if(null!=userVO){
			String roleTypes = "," + type + ",";
			String userType = "," + userVO.getRoleType() + ",";
			if (roleTypes.indexOf(userType) > -1) {
				return EVAL_BODY_INCLUDE;
			} else {
				try {
					out.print("你的权限不够，无法查看到测试内容<br/>");
				} catch (Exception e) {
					throw new JspException(e.getMessage());
				}
			}
		}else{
			try {
				out.print("未登录状态");
			} catch (Exception e) {
				throw new JspException(e.getMessage());
			}
		}
		return SKIP_BODY;
	}

	public int doAfterBodyTag() throws JspException {
		return SKIP_BODY;
	}

	@Override
	public int doEndTag() {
		return EVAL_PAGE;
	}

	@Override
	public void release() {
		super.release();
		type = null;
	}
	
	private void loginOut(){
		
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

}
